﻿using ArticleandSiteData;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x804 上介绍了“空白页”项模板

namespace Dong
{
    /// <summary>
    /// 可用于自身或导航至 Frame 内部的空白页。
    /// </summary>
    public sealed partial class MainPage : Page
    {
        List<Imageinfo> lists = new List<Imageinfo>();
        public MainPage()
        {
            this.InitializeComponent();



        }

        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            DataVMClass M = new DataVMClass();
            await M.Getcategorylist(listimg);
            await M.Getserieslist(serieslistimg);
            listimg.SelectedIndex = 0;
            base.OnNavigatedTo(e);
        }
        Rootobject m;
        private async void listimg_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string str = listimg.SelectedValue.ToString();
            string querystr = "https://api.bmob.cn/1/classes/imageinfo?where={\"imagecategory\":" + "\"" + str + "\"}";
            string result = await RequestHelper.GetHttpstringrequest(querystr);
            m = JsonConvert.DeserializeObject<Rootobject>(result);
            Tile2.ItemsSource = m.results;
            Tile2.ExtraRandomDuration = TimeSpan.FromSeconds(0.5);




        }

        private void list_click(object sender, RoutedEventArgs e)
        {
            gridPhotoscontrol.Visibility = Visibility.Visible;
            Tile2.Visibility = Visibility.Collapsed;
            gridPhotoscontrol.ItemsSource = m.results;
        }

        private void play_click(object sender, RoutedEventArgs e)
        {
            gridPhotoscontrol.Visibility = Visibility.Collapsed;
            Tile2.Visibility = Visibility.Visible;
        }

        private async void serieslistimg_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string str = serieslistimg.SelectedValue.ToString();
            string querystr = "https://api.bmob.cn/1/classes/seriesimagedetail?where={\"seriesname\":" + "\"" + str + "\"}";
            string result = await RequestHelper.GetHttpstringrequest(querystr);
            seriesimagedetailobject seriesnameobj = JsonConvert.DeserializeObject<seriesimagedetailobject>(result);
            Tile2.ItemsSource = seriesnameobj.results;          
        }

        private async void upload_click(object sender, RoutedEventArgs e)
        {
            int newViewId = 0;
            CoreApplicationView newView = CoreApplication.CreateNewView();
            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var newWindow = Window.Current;
                var newAppView = ApplicationView.GetForCurrentView();
                Frame frame = new Frame();
                frame.Navigate(typeof(Uploadimage));
                newWindow.Content = frame;
                newWindow.Activate();
                newViewId = newAppView.Id;
            });
            bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
        }
    }


    public class categorobject
{
    public Imageinfo[] results { get; set; }
}

public class Imageinfo
{
    public string categoryname { get; set; }
    public string createdAt { get; set; }
    public string isinuse { get; set; }
    public string objectId { get; set; }
    public string updatedAt { get; set; }
}
    public class Rootobject
    {
        public ImageinfoDetail[] results { get; set; }
    }

    public class ImageinfoDetail
    {
        public string createdAt { get; set; }
        public string imagecategory { get; set; }
        public string imagetext { get; set; }
        public string imageurl { get; set; }
        public string objectId { get; set; }
        public string siteurl { get; set; }
        public string updatedAt { get; set; }
    }

    public class seriesimageobject
    {
        public seriesinfo[] results { get; set; }
    }

    public class seriesinfo
    {
        public string name_sereis { get; set; }
        public string category { get; set; }
        public string des { get; set; }
        public string author { get; set; }
        public string objectId { get; set; }
        public string updatedAt { get; set; }
    }
    public class seriesimagedetailobject
    {
        public seriesimagedetail[] results { get; set; }
    }

    public class seriesimagedetail
    {
        public string seriesname { get; set; }
        public string imageurl { get; set; }
        public string imagedes { get; set; }   
        public string objectId { get; set; }
        public string updatedAt { get; set; }
    }

}


